import hashlib

from db.aiomysql_connector import AioMysqlClient
from test.test_utils import TestUtils


async def connect_mysql():
    mysql_client = AioMysqlClient(**{
        'host': '127.0.0.1',
        'port': 3306,
        'user': 'root',
        'password': '123456',
        'db_name': 'DatabaseCDXX',
    })
    await mysql_client.init_pool()
    return mysql_client


async def mock_production_data():
    mysql_client = await connect_mysql()
    table = 'Production'
    sql = ("insert into Production(data100,data101,data102,data103,data104,data105,data106,"
           "data107,data108,data109,data110) values (%s, %s, %s, %s, %s, %s ,%s ,%s, %s, %s, %s)")
    await mysql_client.insert(sql, args=(
        '00005', '00005', 'test5', '000005', '2024-05-14 09:01:00', '1', '1', '1', '1', '1', '1'))


async def mock_station_data():
    mysql_client = await connect_mysql()
    table = 'Station'
    sql = ("insert into Station(data600,data601) values (%s, %s)")
    await mysql_client.insert(sql, args=('110', '000011111111111111111',))


async def mock_alarm_data():
    mysql_client = await connect_mysql()
    table = 'Alarm'
    sql = ("insert into Alarm(data100,data101,data102,data103,data104) values (%s, %s,%s, %s,%s)")
    await mysql_client.insert(sql,
                              args=('baojingxinxi', '2024-05-15 10:01:00', '2024-05-16 10:01:00', '成品库', '一般警告'))


async def mock_user_data():
    mysql_client = await connect_mysql()
    # 创建 SHA-256 哈希对象
    hasher = hashlib.sha256()
    # 将密码作为字节串传递给哈希对象
    password = '123456'
    hasher.update(password.encode('utf-8'))
    # 获取哈希值的十六进制表示
    encrypted_password = hasher.hexdigest()
    print(encrypted_password)
    # table = 'User'
    # sql = ("insert into User(username,password,level,created_time,update_time) values (%s, %s,%s, %s,%s)")
    # await mysql_client.insert(sql,
    #                           args=('test1', encrypted_password, '2', '2024-05-15 10:01:00', '2024-05-15 10:01:00'))


async def mock_plc_data():
    mysql_client = await connect_mysql()
    table = 'PLC'
    sql = ("insert into PLC values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,"
           "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)")
    await mysql_client.insert(sql, args=(
        'r1test', 'r1test', 'r1test', 'r1test', 'r1test', 'r1test', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
        '1', '1', '1', 'r2test', 'r2test', 'r2test', 'r2test', 'r2test', 'r2test', '1', '1', '1', '1', '1', '1', '1',
        '1', '1', '1', '1', '1', '1', '1', 'r3test', 'r3test', 'r3test', 'r3test', 'r3test', 'r3test', '1', '1', '1',
        '1', 'r4test', 'r4test', 'r4test', 'r4test', 'r4test', 'r4test', '1', '1', '1', '1', 'r5test', 'r5test',
        'r5test', 'r5test', 'r5test', 'r5test', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
        '1', '1', '1', '1', '1', '1', 'avgtest', 'avgtest', 'avgtest', 'avgtest', 'avgtest', 'avgtest', 'avgtest', '1',
        '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'
    ))


if __name__ == "__main__":
    TestUtils.run_async(mock_user_data())
